#include<stdio.h>

struct collectinfo{
    char dir[80];
    char pst[80];
    char board[80];
    char title[80];
    char owner[80];
    int edittime;
};

int main(){
    char dir[80];
    char* pst = "M.1322906121.A";
    char* board = "notepad";
    FILE *fp = NULL;
    sprintf(dir,"%s","/home/villasy/collect");
    fp = fopen(dir,"a+");
    //printf("%i",check_collected(fp,pst,board));
    print_collect(fp);
    return 0;
}
void print_collect(FILE *fp){
    char line[500],collect[5][80];
    int i,j,n,k;
    while(fgets(line,sizeof(line),fp) != NULL){
        line[strlen(line)-1] = '\0';
        k = j = i = n = 0;
        for(;i<=strlen(line);i++){
            if(line[i] == ',' || line[i] == '\0'){
                memset(collect,0,sizeof(collect));
                for(k=0;k<i-j;k++){
                    collect[n][k] = line[j+k];
                }    
                printf("%s\n",collect[n]);
                j = i+1;
                n++;
            }
        }
    }
}
int check_collected(FILE *fp,char* pst,char* board){
    char line[500],tmp[80];
    int i,j,n,k;
    struct collectinfo *info = NULL;
    while(fgets(line,sizeof(line),fp) != NULL){
        line[strlen(line)-1] = '\0';
        j = i = n = 0;
        while(line[i++] != '\0' && n < 2){
            if(line[i] == ','){
                memset(tmp,0,sizeof(tmp));
                for(k=0;k<i-j;k++){
                    tmp[k] = line[j+k];
                }    
                //cmp board
                if(0 == n){
                    if(strcmp(tmp,pst)){
                        break;
                    }
                }
                //cmp post id
                else if(1 == n){
                    if(!strcmp(tmp,board)){
                        return 1;
                    }
                }
                j = i+1;
                n ++;
            }
        }
    }
    return -1;
}
    /*
    while(fscanf(fp,"%s,%s,%s,%s,%i\n",pst,board,title,owner,edittime) != EOF){
        fgetc(fp);
        printf("%s\n",pst);
        //printf("%s,%s,%s,%s,%i\n",pst,board,title,owner,edittime);
    }
    */
